package com.ruoyi.project.system.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Anonymous;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.SiyuQuery;
import com.ruoyi.project.system.domain.vo.UserChargeVo;
import com.ruoyi.project.system.mapper.SiyuChargeMapper;
import com.ruoyi.project.system.mapper.SiyuQueryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * 收费记录Controller
 */
@RestController
@RequestMapping("/system/charge")
public class SiyuChargeController extends BaseController {

    @Autowired
    private SiyuChargeMapper siyuChargeMapper;

    @Autowired
    private SiyuQueryMapper siyuQueryMapper;

    @Anonymous
    @GetMapping("/referAuth")
    public AjaxResult referAuth(Integer ID, String ac) {
        SiyuQuery siyuQuery = siyuQueryMapper.selectSiyuQueryByQueryId(ID);
        return success(siyuChargeMapper.selectResult(siyuQuery.getUserId(), ac));
    }

    /**
     * 查询收费记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:charge:list')")
    @GetMapping("/subList")
    public TableDataInfo subList(UserChargeVo userChargeVo) {
        startPage();
        List<UserChargeVo> list = siyuChargeMapper.subChargeList(userChargeVo);
        return getDataTable(list);
    }

    /**
     * 查询收费记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:charge:list')")
    @GetMapping("/subListByParent")
    public TableDataInfo subListByParent(UserChargeVo userChargeVo) {
        userChargeVo.setParent(SecurityUtils.getUserId());
        startPage();
        List<UserChargeVo> list = siyuChargeMapper.subChargeList(userChargeVo);
        return getDataTable(list);
    }

}
